home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form frmMain
- BackColor = &H00C0C0C0&
- Caption = "Display Program Directory"
- ClientHeight = 3180
- ClientLeft = 5925
- ClientTop = 2235
- ClientWidth = 6255
- Height = 3585
- Left = 5865
- LinkTopic = "Form1"
- ScaleHeight = 3180
- ScaleWidth = 6255
- Top = 1890
- Width = 6375
- Begin CommandButton cmdClose
- Caption = "Close"
- Height = 435
- Left = 2415
- TabIndex = 2
- Top = 2415
- Width = 1485
- End
- Begin Label Label1
- Alignment = 2 'Center
- BackColor = &H00008000&
- Caption = "Version 1.0, 09/08/93 Comments to Sven Schreiber CIS 100115,2260"
- Height = 645
- Left = 1785
- TabIndex = 5
- Top = 1575
- Width = 2745
- WordWrap = -1 'True
- End
- Begin Label lblPathText
- Alignment = 1 'Right Justify
- BackColor = &H00C0C0C0&
- Caption = "Program directory:"
- Height = 225
- Left = 210
- TabIndex = 4
- Top = 945
- Width = 1590
- End
- Begin Label lblProgramText
- Alignment = 1 'Right Justify
- BackColor = &H00C0C0C0&
- Caption = "EXE filename:"
- Height = 225
- Left = 525
- TabIndex = 3
- Top = 630
- Width = 1275
- End
- Begin Label lblExe
- BackColor = &H00C0C0C0&
- Caption = "EXE name"
- Height = 225
- Left = 1995
- TabIndex = 1
- Top = 630
- Width = 4005
- End
- Begin Label lblPath
- BackColor = &H00C0C0C0&
- Caption = "directory"
- Height = 225
- Left = 1995
- TabIndex = 0
- Top = 945
- Width = 4005
- End
- Option Explicit
- ' This form contains two (general) functions which can
- ' be easily transfered to a global module or another
- ' form.
- ' Please remember to copy the following declarations as well.
- ' While in the VB programming environment the functions
- ' will only return the path of VB.
- ' These two functions are needed to get the neccessary
- ' information.
- Declare Function GetWindowWord Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Integer
- Declare Function GetModuleFileName Lib "Kernel" (ByVal hModule As Integer, ByVal lpFilename As String, ByVal nSize As Integer) As Integer
- ' The GetModuleFileName Function is the most important.
- ' It returns the full path (including) the filename
- ' of the applications whose handle is passed as an argument
- ' As VB does not provide an instance handle the GetWindowWord
- ' Function is needed.
- Sub cmdClose_Click ()
- End
- End Sub
- Sub Form_Load ()
- ' Display the two labels
- lblExe.Caption = GetExeFileName((frmMain.hWnd))
- lblPath.Caption = GetProgramDirectory((frmMain.hWnd))
- End Sub
- ' The argument hWnd is the handle of the form
- Function GetExeFileName (hWnd As Integer) As String
- ' Needed as an argument to the GetWindowWord function
- Const GWW_HINSTANCE = (-6)
- ' Just good programming practice
- Const MAX_PATH_LENGTH = 128
- ' Buffer for the filename
- Dim FileName As String * MAX_PATH_LENGTH
- Dim Chars As Integer
- ' Chars contains the number of returned characters
- Chars = GetModuleFileName(GetWindowWord(hWnd, GWW_HINSTANCE), FileName, MAX_PATH_LENGTH)
- ' Extract the filename
- Do While ((Chars > 0) And Mid$(FileName, Chars, 1) <> "\")
- Chars = Chars - 1
- Loop
- GetExeFileName = Trim$(Right$(FileName, Len(FileName) - Chars))
- End Function
- ' The argument hWnd is the handle of the form
- Function GetProgramDirectory (hWnd As Integer) As String
- ' Needed as an argument to the GetWindowWord function
- Const GWW_HINSTANCE = (-6)
- ' Just good programming practice
- Const MAX_PATH_LENGTH = 128
- ' Buffer for the filename
- Dim FileName As String * MAX_PATH_LENGTH
- Dim Chars As Integer
- ' Chars contains the number of returned characters
- Chars = GetModuleFileName(GetWindowWord(hWnd, GWW_HINSTANCE), FileName, MAX_PATH_LENGTH)
- ' Extract the directory
- Do While ((Chars > 0) And Mid$(FileName, Chars, 1) <> "\")
- Chars = Chars - 1
- Loop
- GetProgramDirectory = Left$(FileName, Chars)
- End Function
-